package com.bdrm.controller.admin;

import com.bdrm.result.Result;
import com.bdrm.service.ReportService;
import com.bdrm.vo.OrderReportVO;
import com.bdrm.vo.SalesTop10ReportVO;
import com.bdrm.vo.TurnoverReportVO;
import com.bdrm.vo.UserStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;


@RestController
@Slf4j
@RequestMapping("/admin/report")
@Api(tags = "数据统计")
public class ReportController {

    @Autowired
    private ReportService  reportService;


    @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额")
    public Result<TurnoverReportVO> turnoverStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end ){
        log.info("营业额查询开始{},{}",begin,end);
        TurnoverReportVO trVO = reportService.turnoverStatistics(begin, end);
        return Result.success(trVO);
    }

    @GetMapping("/userStatistics")
    @ApiOperation("用户统计")
    public Result<UserStatisticsVO> userStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end ){
        log.info("营业额查询开始{},{}",begin,end);

        return Result.success(reportService.getUserStatistics(begin, end));
    }

    @GetMapping("/orderStatistics")
    @ApiOperation("订单统计")
    public Result<OrderReportVO> orderStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end ){
        log.info("营业额查询开始{},{}",begin,end);

        return Result.success(reportService.getOrderStatistics(begin, end));
    }

    @GetMapping("/top10")
    @ApiOperation("销量top10")
    public Result<SalesTop10ReportVO> top10(
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end ){
        log.info("营业额查询开始{},{}",begin,end);

        return Result.success(reportService.getTop10(begin, end));
    }
}
